﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBMode
{
    public class MemberMethod : IMethods<Member>
    {
        public int Add(Member t)
        {
            using (CMSDBEntities cMSDB = new CMSDBEntities())
            {
                if (t == null) return 0;
                t.CreateTime = DateTime.Now;
                cMSDB.Member.Add(t);
                int a = cMSDB.SaveChanges();
                return a;
            }
        }

        public int Delete(Member t)
        {
            throw new NotImplementedException();
        }

        public List<Member> Query()
        {
            using (CMSDBEntities cMSDB = new CMSDBEntities())
            {
                return cMSDB.Member.ToList();
            }
        }

        public int Update(Member t)
        {
            using (CMSDBEntities cMSDB = new CMSDBEntities())
            {
                int a = 0;
                if (t == null) return 0;
                var model = cMSDB.Member.ToList().FirstOrDefault(i => i.Id == t.Id);
                if (model != null)
                {
                    model.Name = t.Name;
                    model.Role = t.Role;
                    a = cMSDB.SaveChanges();
                    return a;
                }
                return a;
            }
        }
    }
}
